package org.hit.burkun.network.tester;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;

import org.hit.burkun.file.FileHelper;
import org.hit.burkun.network.EdgeInfo;
import org.hit.burkun.network.SerializableGraph;
import org.hit.burkun.swalk.SeribaleGraphAdpater;

public class NoLapcRandomWalkTester10 {

	public static void main(String[] args) {
//		doTest9Score();
//		doTest10Score();
		doTest8Score();
//		caclc();
	}
	
	
	
	
	public static void doTest10Score(){
		//注意改变Adapter的特征提取函数
		double[] para = {1.39663765146761,1.2983665196144234,0.8306157757989625,-2.3966749814164308,-0.1237683165752631,-2.1098385175795236,-0.47710384670192185,-1.9182904797090283, 0.09373620104314367, 0.027135662297271056 }; 
		double alpha = 0.2;
		doPrWeightOpt(para, alpha);
		doPrWeightOptV(para, alpha);
		caclc();
	}
	
	public static void doTest9Score(){
		//注意改变Adapter的特征提取函数
		double[] para = {
				0.45584890857378424
				,0.20192175376194918
				,1.3255802114514927
				,-2.1847926173948435
				,-1.4563568837131768
				,-0.2777684447732944
				,-0.9510680915047385
				,-0.5092351055112398
				,-0.052307843638701355
		}; 
		double alpha = 0.9;
		doPrWeightOpt(para, alpha);
		doPrWeightOptV(para, alpha);
		//caclc();
	}
	
	
	public static void doTest8Score(){
		//注意改变Adapter的特征提取函数
		double[] para = {0.767535960050006
				,0.6951968369349969
				,0.13076814724053054
				,-0.3997666587731018
				,0.4161687239612133
				,-0.9343320280282522
				,-0.4875851925097461
				,-0.5638407641586947}; 
		double alpha = 0.2;
		doPrWeightOpt(para, alpha);
//		doPrNoweight();
//		doPrWeight(8);
		doPrWeightOptV(para, alpha);
//		doPrNoweightV();
//		doPrWeightV(8);
//		caclc();
	}
	
	public static void doTest8noScore(){
		//注意改变Adapter的特征提取函数
		double[] para = {1.5940996782550036, 1.334241847895625, 0.9045551159252517, -2.525140196051825, -0.12547323844836294 ,-2.2241020582422752, -0.5701761153261528, -1.963770011256985 }; 
		double alpha = 0.2;
		doPrWeightOpt(para, alpha);
		doPrNoweight(alpha);
		doPrWeight(8,alpha);
		doPrWeightOptV(para, alpha);
		doPrNoweightV(alpha);
		doPrWeightV(8, alpha);
		caclc();
	}
	
	
	public static void caclc(){
		System.out.println(ValidData.calcAuc("data/linkpredict/t-weigth-salpha-0.2-sample-1.0-opt.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/t-no-weigth-salpha-0.2-sample-1.0-noweight.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/t-weigth-salpha-0.2-sample-1.0-allone.txt"));
		
		System.out.println(ValidData.calcAuc("data/linkpredict/v-weigth-salpha-0.2-sample-1.0-opt.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/v-no-weigth-salpha-0.2-sample-1.0-noweight.txt"));
//		System.out.println(ValidData.calcAuc("data/linkpredict/v-weigth-salpha-0.2-sample-1.0-allone.txt"));
	}
	
	
	public static void doPrNoweightV(double salpha){
		//删掉所有的，包括验证集合测试集
		//HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		//HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueValidObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseValidObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		double[] para = new double[]{1};
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, false);
		writeToFile("data/linkpredict/v-no-weigth-salpha-" + salpha + "-sample-1.0-noweight" +".txt", res);
		//writeToFile("data/linkpredict/v-no-weigth-salpha-" + salpha + "-sample-0.5-noweight" +".txt", res);

	}
	
	private static void writeToFile(String fileName, LinkedList<String> lines){
		FileHelper.writeFile(fileName, lines);
	}

	
	public static void doPrWeightV(int fnum,double salpha){
//		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
//		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueValidObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseValidObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		double[] para = new double[fnum];
		for(int i=0; i < fnum; i++){
			para[i] = 1;
		}
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-1.0-allone-"+salpha +".txt", res);
		//writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-0.5-allone" +".txt", res);
	}
	
	public static void doPrWeightOptV(double[] para, double salpha){
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueValidObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseValidObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-1.0-opt-"+salpha +".txt", res);
		//writeToFile("data/linkpredict/v-weigth-salpha-" + salpha + "-sample-0.5-opt" +".txt", res);
	}
	
	
	public static void doPrNoweight(double salpha){
		//删掉所有的，包括验证集合测试集
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		
		double[] para = new double[]{1};
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, false);
		writeToFile("data/linkpredict/t-no-weigth-salpha-" + salpha + "-sample-1.0-noweight-"+salpha +".txt", res);
		//writeToFile("data/linkpredict/t-no-weigth-salpha-" + salpha + "-sample-0.5-noweight" +".txt", res);
	}
	
	
	public static void doPrWeight(int fnum, double salpha){
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		
		double[] para = new double[fnum];
		for(int i=0; i < fnum; i++){
			para[i] = 1;
		}
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-1.0-allone-"+salpha +".txt", res);
		//writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-0.5-allone" +".txt", res);
	}
	
	public static void doPrWeightOpt(double[] para, double salpha){
		HashMap<String, HashSet<EdgeInfo>> testTrueTrain = ValidData.readTestTrueTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testFalseTrain = ValidData.readTestFalseTrainObj();
		HashMap<String, HashSet<EdgeInfo>> testTrue = ValidData.readTestTrueObj();
		SerializableGraph sg  = ValidData.getRemovedSg(false, testTrue);
		double eps = 1e-4;
		LinkedList<String> res = SeribaleGraphAdpater.getRandomWalkWithRestartTrainValue(para, testTrueTrain,testFalseTrain, sg, eps, salpha, true);
		writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-1.0-opt-" + salpha +".txt", res);
		//writeToFile("data/linkpredict/t-weigth-salpha-" + salpha + "-sample-0.5-opt" +".txt", res);
	}
	
}
